package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.PubCenter;
import com.sfzy.service.PubCenterService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PubCenterController
 * @Description TODO
 * @Author niejiacan
 * @Date 2025年08月14日 11:42
 * @Version 1.0
 */
@RestController
@RequestMapping("pubCenter")
public class PubCenterController {

    @Autowired
    private PubCenterService pubCenterService;

    @PostMapping
    public R addPubCenter(@RequestBody PubCenter pubCenter){
        int i = pubCenterService.addPubCenter(pubCenter);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @PutMapping()
    public R updatePubCenter(@RequestBody PubCenter pubCenter){
        int i = pubCenterService.updatePubCenter(pubCenter);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deletePubCenter(@PathVariable("id") int id){
        int i = pubCenterService.deletePubCenter(id);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @GetMapping("{id}")
    public R selectPubCenter(@PathVariable("id") int id){
        PubCenter pubCenter = pubCenterService.selectPubCenter(id);
        return R.ok(pubCenter);
    }

    @GetMapping("pageNameContent")
    public R pageNameContent(PubCenter pubCenter,
                             @RequestParam(required = false,defaultValue = "1") int pageNum,
                             @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<PubCenter> pubCenterPageInfo = pubCenterService.pageNameContent(pubCenter, pageNum, pageSize);
        return R.ok(pubCenterPageInfo);
    }










}
